home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Timeline / Stop Timeline.js < prev   
Encoding:
Text File  |  1999-12-01  |  4.1 KB  |  132 lines

  1. //*************** GLOBALS VARS *****************
  2.  
  3. var helpDoc = MM.HELP_behStopTimeline;
  4.  
  5. //******************* BEHAVIOR FUNCTION **********************
  6.  
  7. //Stops one or all timelines if they are currently playing.
  8. //Accepts the following arguments:
  9. //  tmLnName - (optional) the name of the timeline to stop (ex: Timeline1)
  10. //             if no timeline name is passed, stops all timelines
  11. //
  12. //Designed to work in conjunction with Dreamweaver's Timeline Inspector.
  13. //The Timeline Inspector creates a JS function called MM_initTimelines(),
  14. //which puts all the timeline settings in a multidimensional array, saved
  15. //into a document property called document.MM_Time.
  16. //
  17. //My function stops one or all by setting their IDs to null. Play Timeline
  18. //always checks ID after each iteration, so any outstanding timers will
  19. //stop with the next function call.
  20.  
  21. function MM_timelineStop(tmLnName) { //v1.2
  22.   //Copyright 1997 Macromedia, Inc. All rights reserved.
  23.   if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  24.   if (tmLnName == null)  //stop all
  25.     for (var i=0; i<document.MM_Time.length; i++) document.MM_Time[i].ID = null;
  26.   else document.MM_Time[tmLnName].ID = null; //stop one
  27. }
  28.  
  29.  
  30. //******************* API **********************
  31.  
  32.  
  33. //Checks for the existence of timelines.
  34. //If none exist, returns false so this Action is grayed out.
  35.  
  36. function canAcceptBehavior(){
  37.   var allScripts,i,theScript,timelineExists;
  38.  
  39.   timelineExists = false;
  40.   allScripts = getObjectTags("document","script");
  41.   for (i in allScripts) {
  42.     theScript = ""+allScripts[i];
  43.     if (theScript.indexOf("function MM_initTimelines") != -1) {
  44.       timelineExists = true;
  45.       break;
  46.   } }
  47.   return (timelineExists);
  48. }
  49.  
  50.  
  51.  
  52. //Returns a Javascript function to be inserted in HTML head with script tags.
  53.  
  54. function behaviorFunction(){
  55.   return "MM_timelineStop";
  56. }
  57.  
  58.  
  59.  
  60. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  61. //Returns one arg: the selected timeline name. If ** ALL TIMELINES **
  62. //was selected, returns no arguments.
  63.  
  64. function applyBehavior() {
  65.   menuIndex = document.theForm.menu.selectedIndex;  //get menu selection index
  66.   if (menuIndex == 0) { //stop ALL timelines, return no arg
  67.     return "MM_timelineStop()";
  68.   } else {
  69.     timelineName = document.theForm.menu.options[menuIndex].text; //gets selection
  70.     return "MM_timelineStop('"+timelineName+"')";
  71.   }
  72. }
  73.  
  74.  
  75.  
  76. //Passed the function call above, extracts the args and reloads the UI.
  77. //With arg timelineName, scans the menu for a matching item, and selects it.
  78. //If the name is not found, it gives an error msg.
  79.  
  80. function inspectBehavior(upStr){
  81.   var timelineName,menuLength,i;
  82.   var argArray = new Array;
  83.   var found = false;
  84.  
  85.   argArray = extractArgs(upStr); //get args
  86.   if (argArray.length == 2) {  //should be exactly 2 args
  87.     timelineName = argArray[1];
  88.     menuLength = document.theForm.menu.options.length;
  89.     for (var i=0; i<menuLength; i++) {  //search menu for matching timeline name
  90.       if (document.theForm.menu.options[i].text == timelineName) { //if found
  91.         document.theForm.menu.selectedIndex = i;  //make it selected
  92.         found = true;
  93.         break;
  94.       }
  95.     }
  96.     if (!found) alert(errMsg(MSG_TimelineNotFound,timelineName));
  97.   }
  98. }
  99.  
  100.  
  101.  
  102. //***************** LOCAL FUNCTIONS  ******************
  103.  
  104.  
  105. //Load the select menu with timeline names.
  106.  
  107. function initializeUI(){
  108.   var i,j,startPos,endPos,theScript;
  109.   var theName="";
  110.   var menuIndex = 0;
  111.   var allScripts = new Array;
  112.  
  113.   allScripts = getObjectTags("document","script");
  114.   for (i in allScripts) {
  115.     theScript = ""+allScripts[i];
  116.     if (theScript.indexOf("function MM_initTimelines") != -1) {
  117.       j = theScript.indexOf('].MM_Name');
  118.       while (j != -1) {
  119.         startPos = theScript.indexOf('"',++j);
  120.         endPos = theScript.indexOf('"',++startPos);
  121.         if (0 < startPos && startPos < endPos) {
  122.           if (theName=="") //first one, insert ALL option
  123.             document.theForm.menu.options[menuIndex++] = new Option("** "+MENUITEM_AllTimelines+" **");
  124.           theName = theScript.substring(startPos,endPos);
  125.           document.theForm.menu.options[menuIndex++] = new Option(theName);
  126.         }
  127.         j = theScript.indexOf('].MM_Name',j+1);
  128.       }
  129.     }
  130.   }
  131. }
  132.